package com.cloudspace.jindun.network.api;

import com.cloudspace.jindun.config.Configs;
import com.cloudspace.jindun.model.NoticeMessageResult;
import com.cloudspace.jindun.model.NoticePersonResult;
import com.cloudspace.jindun.network.HttpManager;
import com.cloudspace.jindun.network.base.ApiCallback;
import com.cloudspace.jindun.network.base.GsonRequest;
import com.cloudspace.jindun.network.base.RequestFactory;

import java.io.Serializable;

/**
 * Created by zengxianhua on 17/3/22.
 */

public class NoticeApi extends BaseAPI implements Serializable{
    public  String getBaseUrl(){
        return String.format("http://%s/jindun/%s/message/",
                Configs.SERVER_IP, Configs.API_VERSION);
    }

    public void getNoticeReadPerson(String tag, String msgId,
                                    String userId, String groupId, ApiCallback<NoticePersonResult> callback){
        String url = getBaseUrl() + "lookOpenList";

        GsonRequest request = RequestFactory.newInstance()
                .createPost(url, NoticePersonResult.class, callback)
                .setParams("userId", userId)
                .setParams("groupId", groupId)
                .setParams("msgId", msgId)
                .setNoCache();
        HttpManager.addRequest(request, tag);
    }

    public void sentNotification(String tag, String msgId, String userId, String groupId,
                                 ApiCallback<NoticeMessageResult> callback){
        String url = getBaseUrl() + "sentNotification";

        GsonRequest request = RequestFactory.newInstance()
                .createPost(url, NoticeMessageResult.class, callback)
                .setParams("userId", userId)
                .setParams("groupId", groupId)
                .setParams("msgId", msgId)
                .setNoCache();
        HttpManager.addRequest(request, tag);
    }

    public void openNotification(String tag, String msgId, String userId, String groupId,
                                 ApiCallback<NoticeMessageResult> callback){
        String url = getBaseUrl() + "openNotification";

        GsonRequest request = RequestFactory.newInstance()
                .createPost(url, NoticeMessageResult.class, callback)
                .setParams("userId", userId)
                .setParams("groupId", groupId)
                .setParams("msgId", msgId)
                .setNoCache();
        HttpManager.addRequest(request, tag);
    }
}
